//
//  Common.swift
//  test
//
//  Created by lyl on 2020/7/8.
//  Copyright © 2020年 lyl. All rights reserved.
//

import UIKit
//MARK: - 接口
//内网url
let kUrl = "http://gtest.luyiwangluo.com/apiwl/v1"//测试
//let kUrl = "https://test.luyiwangluo.com/apiwl/v1"//测试
let imgUrl = "https://test.luyiwangluo.com/upload/uniapp"//网络图片路径

//外网url
//let kUrl = "https://api.luyiwangluo.com/apiwl/v1"//正式

//MARK: - 颜色
let color_241_117_34 = rgba(241, 117, 34, 1)
let color_230_0_18 = kColor(230, 117, 34, 1)
let color_17 = UIColor(red: 17/255.0, green: 17/255.0, blue: 17/255.0, alpha: 1)
let color_236_118_75 = UIColor(red: 236/255.0, green: 118/255.0, blue: 75/255.0, alpha: 1)
let color_255_125_121 = UIColor(red: 255/255.0, green: 125/255.0, blue: 121/255.0, alpha: 1)
let color_220 = UIColor(red: 220/255.0, green: 220/255.0, blue: 220/255.0, alpha: 1)
let color_202_230_253 = UIColor(red: 202/255.0, green: 230/255.0, blue: 253/255.0, alpha: 1)
let color_253_145_42 = UIColor(red: 253/255.0, green: 145/255.0, blue: 42/255.0, alpha: 1)
let color_253_77_8 = UIColor(red: 253/255.0, green: 77/255.0, blue: 8/255.0, alpha: 1)
let color_233_245_254 = UIColor(red: 233/255.0, green: 245/255.0, blue: 254/255.0, alpha: 1)
let color_255_223_71 = UIColor(red: 255/255.0, green: 223/255.0, blue: 71/255.0, alpha: 1)
let color_83_109_230 = UIColor(red: 83/255.0, green: 109/255.0, blue: 230/255.0, alpha: 1)
let color_138_159_255 = UIColor(red: 138/255.0, green: 159/255.0, blue: 255/255.0, alpha: 1)
let color_230_234_255 = UIColor(red: 230/255.0, green: 234/255.0, blue: 255/255.0, alpha: 1)
let color_24_205_243 = UIColor(red: 24/255.0, green: 205/255.0, blue: 243/255.0, alpha: 1)
let color_230_242_252 = UIColor(red: 230/255.0, green: 242/255.0, blue: 252/255.0, alpha: 1)
let color_0_76_136 = UIColor(red: 0/255.0, green: 76/255.0, blue: 136/255.0, alpha: 1)
let color_252_178_89 = UIColor(red: 252/255.0, green: 178/255.0, blue: 89/255.0, alpha: 1)
let color_223_221_219 = UIColor(red: 223/255.0, green: 221/255.0, blue: 219/255.0, alpha: 1)
let color_252_119_119 = UIColor(red: 252/255.0, green: 119/255.0, blue: 119/255.0, alpha: 1)
let color_227_242_253 = UIColor(red: 227/255.0, green: 242/255.0, blue: 253/255.0, alpha: 1)
let color_35_33_40 = UIColor(red: 35/255.0, green: 33/255.0, blue: 40/255.0, alpha: 1)
let color_181_206_229 = UIColor(red: 181/255.0, green: 206/255.0, blue: 229/255.0, alpha: 1)
let color_160 = UIColor(red: 160/255.0, green: 160/255.0, blue: 160/255.0, alpha: 1)
let color_191 = UIColor(red: 191/255.0, green: 191/255.0, blue: 191/255.0, alpha: 1)
let color_150_46_46 = UIColor(red: 150/255.0, green: 46/255.0, blue: 46/255.0, alpha: 1)
let color_118_117_117 = UIColor(red: 118/255.0, green: 117/255.0, blue: 117/255.0, alpha: 1)
let color_99 = UIColor(red: 99/255.0, green: 99/255.0, blue: 99/255.0, alpha: 1)
let color_159_157_157 = UIColor(red: 159/255.0, green: 157/255.0, blue: 157/255.0, alpha: 1)
let color_255_80_0 = UIColor(red: 255/255.0, green: 80/255.0, blue: 0/255.0, alpha: 1)
let color_247_84_23 = UIColor(red: 247/255.0, green: 84/255.0, blue: 23/255.0, alpha: 1)
let color_98_96_96 = UIColor(red: 98/255.0, green: 96/255.0, blue: 96/255.0, alpha: 1)
let color_174_173_173 = UIColor(red: 174/255.0, green: 173/255.0, blue: 173/255.0, alpha: 1)
let color_253_203_2 = UIColor(red: 253/255.0, green: 203/255.0, blue: 2/255.0, alpha: 1)
let color_178_179_179 = UIColor(red: 178/255.0, green: 179/255.0, blue: 179/255.0, alpha: 1)
let color_245_53_9 = UIColor(red: 245/255.0, green: 53/255.0, blue: 9/255.0, alpha: 1)
let color_147_146_146 = UIColor(red: 147/255.0, green: 146/255.0, blue: 146/255.0, alpha: 1)
let color_225_227_228 = UIColor(red: 225/255.0, green: 227/255.0, blue: 228/255.0, alpha: 1)
let color_238_247_255 = UIColor(red: 238/255.0, green: 247/255.0, blue: 255/255.0, alpha: 1)
let color_255_93_0 = UIColor(red: 255/255.0, green: 93/255.0, blue: 0/255.0, alpha: 1)
let color_76_171_247 = UIColor(red: 76/255.0, green: 171/255.0, blue: 247/255.0, alpha: 1)
let color_241_245_255 = UIColor(red: 241/255.0, green: 245/255.0, blue: 248/255.0, alpha: 1)
let color_209_234_255 = UIColor(red: 209/255.0, green: 234/255.0, blue: 255/255.0, alpha: 1)
let color_0_63_113 = UIColor(red: 0/255.0, green: 63/255.0, blue: 113/255.0, alpha: 1)
let color_179_178_253 = UIColor(red: 179/255.0, green: 178/255.0, blue: 178/255.0, alpha: 0.35)
let color_249_248_253 = UIColor(red: 249/255.0, green: 248/255.0, blue: 253/255.0, alpha: 1)
let color_170 = UIColor(red: 170/255.0, green: 170/255.0, blue: 170/255.0, alpha: 1)
let color_86_147_255 = UIColor(red: 86/255.0, green: 147/255.0, blue: 255/255.0, alpha: 1)
let color_255_175_2 = UIColor(red: 255/255.0, green: 175/255.0, blue: 2/255.0, alpha: 1)
let color_169_200_255 = UIColor(red: 169/255.0, green: 200/255.0, blue: 255/255.0, alpha: 1)
let color_250_175_0 = UIColor(red: 250/255.0, green: 175/255.0, blue: 0/255.0, alpha: 1)
let color_251_95_6 = UIColor(red: 251/255.0, green: 95/255.0, blue: 6/255.0, alpha: 1)
let color_50_128_245 = UIColor(red: 50/255.0, green: 128/255.0, blue: 245/255.0, alpha: 1)
let color_126 = UIColor(red: 126/255.0, green: 126/255.0, blue: 126/255.0, alpha: 1)
let color_51 = UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1)
let color_219 = UIColor(red: 219/255.0, green: 219/255.0, blue: 219/255.0, alpha: 1)
let color_153 = UIColor(red: 153/255.0, green: 153/255.0, blue: 153/255.0, alpha: 1)
let color_102 = UIColor(red: 102/255.0, green: 102/255.0, blue: 102/255.0, alpha: 1)
let color_138 = UIColor(red: 138/255.0, green: 138/255.0, blue: 138/255.0, alpha: 1)//字体浅色
let color_221 = UIColor(red: 221/255.0, green: 221/255.0, blue: 221/255.0, alpha: 1)
let color_238 = UIColor(red: 238/255.0, green: 238/255.0, blue: 238/255.0, alpha: 1)//分割线颜色
let mainColor = UIColor(red: 244/255.0, green: 244/255.0, blue: 244/255.0, alpha: 1)//主色
let lightColor = UIColor(red: 115/255.0, green: 115/255.0, blue: 115/255.0, alpha: 1)//字体浅色
let brightColor = UIColor(red: 255/255.0, green: 102/255.0, blue: 76/255.0, alpha: 1)//点睛色
let lineColor = UIColor(red: 202/255.0, green: 212/255.0, blue: 220/255.0, alpha: 1)//分割线颜色
let color_88_87_87 = UIColor(red: 88/255.0, green: 87/255.0, blue: 87/255.0, alpha: 1)
let color_81_173_247 = UIColor(red: 81/255.0, green: 173/255.0, blue: 247/255.0, alpha: 1)

//MARK: - 字体
let font_10 = UIFont.systemFont(ofSize: 10)
let font_11 = UIFont.systemFont(ofSize: 11)
let font_12 = UIFont.systemFont(ofSize: 12)
let font_13 = UIFont.systemFont(ofSize: 13)
let font_14 = UIFont.systemFont(ofSize: 14)
let font_15 = UIFont.systemFont(ofSize: 15)
let font_16 = UIFont.systemFont(ofSize: 16)
let font_17 = UIFont.systemFont(ofSize: 17)
let font_18 = UIFont.systemFont(ofSize: 18)
let font_20 = UIFont.systemFont(ofSize: 20)
let font_22 = UIFont.systemFont(ofSize: 22)
let font_24 = UIFont.systemFont(ofSize: 24)
let font_30 = UIFont.systemFont(ofSize: 30)
let font_45 = UIFont.systemFont(ofSize: 45)

//MARK: - 宽高距离
//起始y坐标
let startY: CGFloat = 0
//卡片控件宽度
let kCardWidth = (kScreenWidth-2*pageMargin)
//屏幕高度
let kScreenHeight = UIScreen.main.bounds.height
//屏幕宽度
let kScreenWidth = UIScreen.main.bounds.width
//内容边距
let contentMargin: CGFloat = 8.0
//页边距
let pageMargin: CGFloat = 15.0
///状态栏高度
let kStatusBarHeight = UIApplication.shared.statusBarFrame.height
///有导航栏的安全区顶部高度
let kSafeAreaTopHeight = CGFloat(UIApplication.shared.statusBarFrame.height+44.0)
///tabbar高度
let kTabBarHeight = CGFloat(kStatusBarHeight == 44.0 ? 83.0 : 49.0)
///安全区底部高度
let kSafeAreaBottomHeight = CGFloat(kTabBarHeight - 49.0)
///有导航栏的安全区高度-iPhoneX适配
let kSafeAreaHeight = kScreenHeight-kSafeAreaTopHeight-kSafeAreaBottomHeight
///没有导航栏的安全区高度
let kNoNavigationBarSafeAreaHeight = kScreenHeight-kStatusBarHeight-kSafeAreaBottomHeight
///有tabbar的安全区高度
let kTabBarSafeAreaHeight = kScreenHeight-kSafeAreaTopHeight-kTabBarHeight

//MARK: - 常用方法
//生成颜色RGB
func kColor(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
func kColor(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
func rgba(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
//生产颜色 可以这样调用：kRGBColorFromHex(0x1D1D26)
func kRGBColorFromHex(hexValue: Int) -> (UIColor) {
    return UIColor(red: ((CGFloat)((hexValue & 0xFF0000) >> 16)) / 255.0, green: ((CGFloat)((hexValue & 0xFF00) >> 8)) / 255.0, blue: ((CGFloat)(hexValue & 0xFF)) / 255.0, alpha: 1.0)
}

//主目录路径
let kDocPath = NSHomeDirectory() + "/Documents"
//易迅状态
var yxStatus = 1
//userId
func getToken() -> String {
    return UserDefaults.standard.string(forKey: "token") ?? ""
}
func getProvience() -> String {
    return UserDefaults.standard.string(forKey: "provience") ?? ""
}
func getCity() -> String {
    return UserDefaults.standard.string(forKey: "city") ?? ""
}
//loginType
func kLoginType() -> String {
    return UserDefaults.standard.string(forKey: "loginType") ?? "0"
}
//name
func kLoginName() -> String {
    return UserDefaults.standard.string(forKey: "name") ?? ""
}
//lat
func getLat() -> Double {
    return UserDefaults.standard.double(forKey: "lat")
}
//lng
func getLng() -> Double {
    return UserDefaults.standard.double(forKey: "lng")
}
//servicePhone
func getServicePhone() -> String {
    return UserDefaults.standard.string(forKey: "servicePhone") ?? ""
}
//searchHistory
func getSearchHistory() -> [String]? {
    return (UserDefaults.standard.array(forKey: "searchHistory") as? [String])
}
//goodsSearchHistory
func getGoodsSearchHistory() -> [String] {
    return (UserDefaults.standard.stringArray(forKey: "goodsSearchHistory") ?? [String]())
}
//networkStatus
func kNetworkStatus() -> (Int){
    return UserDefaults.standard.integer(forKey: "networkStatus")
}

//获取月的天数
func daysOfMonth(year: Int, month: Int) -> Int {
    switch month {
    case 1,3,5,7,8,10,12:
        return 31
    case 4,6,9,11:
        return 30
    case 2:
        if (year % 100 == 0) {
            if (year % 400 == 0) {
                return 29//润年
            }else {
                return 28//平年
            }
        }else {
            if (year % 4 == 0) {
                return 29//闰年
            }else {
                return 28//平年
            }
        }
    default:
        return 0
    }
}
//自定义打印
func MyLog<T>(_ message : T, file : String = #file, funcName : String = #function, lineNum : Int = #line) {
    #if DEBUG
    let fileName = (file as NSString).lastPathComponent
    print("\n[\(fileName)--\(lineNum)行--]:\(message)\n")
    //print("文件:\(fileName)\n方法:\(funcName)\n行号:\(lineNum)\n打印信息\(message)");
    #endif
}

/*
 角色类型
 1 司机 司机界面
 2 货主 司机/货主界面
 3 加油员 商户界面 不能修改商户价格
 4 加油加气管理员 商户界面 修改商户价格
 5 货运商户管理员 货主界面
 6 维修商户管理员 商户界面 修改商品价格
 7 服务站商户管理员 商户界面 修改商品价格
 8 货运商户排队管理员 货主界面 只能操作排队管理
 */
